package com.example.knowledge.mvvm.activity

import android.content.Context
import android.content.Intent
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.knowledge.R
import com.example.knowledge.mvvm.adapter.ReportPagerAdapter
import com.example.knowledge.mvvm.bean.ReportSelectBean
import com.gsafety.libraryktx.base.BaseActivity
import com.gsafety.libraryktx.config.Constant
import com.gsafety.libraryktx.core.RouterConstants
import com.gsafety.libraryktx.manager.UserManager
import kotlinx.android.synthetic.main.know_report_activity_layout.*
import java.util.*

@Route(path = RouterConstants.REPORT_ACTIVITY)
class ReportActivity:BaseActivity() {
    var mtitles=mutableListOf<ReportSelectBean>()
    private var reportVPAdapter: ReportPagerAdapter? = null
    override fun initView() {
        initTab()
        tl_report.setupWithViewPager(vp_pager)
    }


    override fun initData() {
        findViewById<TextView>(R.id.title_name).text = intent.getStringExtra(Constant.Extra_TITLE_KEY)
    }

    override fun getLayoutId(): Int {
        return R.layout.know_report_activity_layout
    }

    //初始化tab
    fun initTab(){
        var loginbean= UserManager.getInstance().getUser()
        var result= Arrays.asList(loginbean?.orgType?.split(","))
        var datas=result[0]
        var type= intent.getStringExtra(Constant.Extra_TYPE_KEY)
        datas?.let {
            if (it.contains(Constant.CODE_WARN_GAS)) {
                mtitles.add(ReportSelectBean("燃气",Constant.CODE_WARN_GAS,type))
            }
            if (it.contains(Constant.CODE_WARN_WS)) {
                mtitles.add(ReportSelectBean("供水",Constant.CODE_WARN_WS,type))
            }
            if (it.contains(Constant.CODE_WARN_PS)) {
                mtitles.add(ReportSelectBean("排水",Constant.CODE_WARN_PS,type))
            }
            if (it.contains(Constant.CODE_WARN_BRIDGE)) {
                mtitles.add(ReportSelectBean("桥梁",Constant.CODE_WARN_BRIDGE,type))
            }
            if (it.contains(Constant.CODE_WARN_HEAT)) {
                mtitles.add(ReportSelectBean("热力",Constant.CODE_WARN_HEAT,type))
            }
        }
        tl_report.isTabIndicatorFullWidth=false
        reportVPAdapter = ReportPagerAdapter(supportFragmentManager,mtitles)
        vp_pager.adapter= reportVPAdapter
        tl_report.setupWithViewPager(vp_pager)
    }

    companion object {
        fun startIntent(ctx: Context,title:String,type:String) {
            val intent = Intent()
            intent.setClass(ctx, ReportActivity::class.java)
            intent.putExtra(Constant.Extra_TITLE_KEY,title)
            intent.putExtra(Constant.Extra_TYPE_KEY,type)
            ctx.startActivity(intent)
        }
    }
}